using System.Data;
using System.Data.SqlClient;
using Provausio.Common.Data;
using Provausio.Common.Objects;

namespace TrainingManagement.api.Models.Data.CRUD.DepartmentTree
{
    public class DepartmentTreeUpdateDataSource : NonQuerySource<BusinessObjects.DepartmentTree>
    {
        public override bool Execute(BusinessObjects.DepartmentTree request)
        {
            const string updateDepartmenTree = "dbo.training_api_DepartmentTreeUpdate";
            var parameters = new SqlParameter[4];
            parameters[0] = new SqlParameter("@LocationID", SqlDbType.Int) {Value = request.LocationId};
            parameters[1] = new SqlParameter("@Parent", SqlDbType.NVarChar){Value = request.ParentId};
            parameters[2] = new SqlParameter("@Child", SqlDbType.NVarChar) { Value = request.ChildId };
            parameters[3] = new SqlParameter("@DepartmentTreeID", SqlDbType.Int){ Value = request.DepartmentTreeId};

            return SqlHelper.ExecuteNonQuery(
                    ConnectionStrings.TrainingDb,
                    CommandType.StoredProcedure,
                    updateDepartmenTree,
                    parameters) != 0;
        }
    }
}